// 引入ajax请求函数
import {
  reqCateList,
  reqSubCateList
} from '@/api'

// 引入mutation类名
import {
  RECEIVE_CATELIST,
  RECEIVE_SUBCATELIST
} from '../mutation-types'

// 定义state
const state = {
  catelist: [],
  subCates: []
}
// 定义mutation
const mutations = {
  [RECEIVE_CATELIST] (state, catelist) {
    state.catelist = catelist
  },
  [RECEIVE_SUBCATELIST](state,subCates){
    state.subCates = subCates
  }
}

// 定义action
const actions = {
  async getCateList ({commit}) {
    const result = await reqCateList()
    const catelist = result.data
    // console.log(catelist)
    commit(RECEIVE_CATELIST, catelist)
  },
  async getSubCateList ({commit}) {
    const result = await reqSubCateList()
    // console.log(result)
    const subCates = result.data
    // console.log(subCates)
    commit(RECEIVE_CATELIST, subCates)
  }
}

// 定义getters
const getters = {

}

// 暴露各个被定义的模块

export default {
  state,
  mutations,
  actions,
  getters
}
